package com.chenjt.jvm.first.two_classLoader;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2025/6/4 10:08
 */
public class DeadThreadTest {
    /**
     * 虚拟机必须保证一个类的<clinit>()方法在多线程下被同步加锁
     * 也就是一个类只会被加载一次
     * @param args
     */
    public static void main(String[] args) {
        Runnable r = ()->{
            System.out.println(Thread.currentThread().getName() + "开始");
            DeadThread dead = new DeadThread();
            System.out.println(Thread.currentThread().getName() + "结束");
        };
        Thread t1 = new Thread(r, "线程1");
        Thread t2 = new Thread(r, "线程2");
        t1.start();
        t2.start();
    }
}
class DeadThread {
    static {
        if (true) {
            System.out.println(Thread.currentThread().getName() + "初始化当前类");
            while (true) {

            }
        }
    }
}
